﻿@{
    ViewBag.Title = "公司管理";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script src="~/Content/Scripts/jqgrid/grid.treegrid.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        GetGrid();
    });
    //加载表格
    function GetGrid() {
        $("#gridTable").jqGrid({
            url: "@Url.Content("~/CommonModule/Company/TreeGridListJson")",
            datatype: "json",
            treeGrid: true,
            treeGridModel: "nested",
            ExpandColumn: "Code",
            height: $(window).height() - 77,
            autowidth: true,
            colModel: [
            { label: '主键', name: 'CompanyId', index: 'CompanyId', width: 80, hidden: true },
            { label: "名称", name: "FullName", index: "FullName", width: 200 },
            { label: "编码", name: "Code", index: "Code", width: 100 },
            { label: "简称", name: "ShortName", index: "ShortName", width: 100 },
            { label: "分类", name: "Category", index: "Category", width: 50, align: "center" },
            { label: "联系人", name: "Contact", index: "Contact", width: 100 },
            { label: "电话", name: "Phone", index: "Phone", width: 100 },
            { label: "传真", name: "Fax", index: "Fax", width: 100 },
            {
                label: '有效', name: 'Enabled', index: 'Enabled', width: 45, align: 'center',
                formatter: function (cellvalue, options, rowObject) {
                    if (cellvalue == '1') return "<img src='../../Content/Images/checkokmark.gif'/>";
                    if (cellvalue == '0') return "<img src='../../Content/Images/checknomark.gif'/>";
                }
            },
            { label: '描述', name: 'Remark', index: 'Remark', width: 500 }
            ],
            pager: "false",
            rowNum: 1000,
            rownumbers: true,
            shrinkToFit: false
        });
        columnModelData("#gridTable");
    }
    //新增
    function btn_add() {
        var CompanyId = GetJqGridRowValue("#gridTable", "CompanyId");
        if (!CompanyId) {
            CompanyId = 0;
        }
        var url = "/CommonModule/Company/Form?CompanyId=" + CompanyId;
        openDialog(url, "Form", "新增公司", 650, 380, function (iframe) {
            top.frames[iframe].AcceptClick()
        });
    }
    //编辑
    function btn_edit() {
        var KeyValue = GetJqGridRowValue("#gridTable", "CompanyId");
        if (IsChecked(KeyValue)) {
            var url = "/CommonModule/Company/Form?KeyValue=" + KeyValue;
            openDialog(url, "Form", "编辑公司", 650, 380, function (iframe) {
                top.frames[iframe].AcceptClick();
            });
        }
    }
    //删除
    function btn_delete() {
        var KeyValue = GetJqGridRowValue("#gridTable", "CompanyId");
        if (IsDelData(KeyValue)) {
            var delparm = 'KeyValue=' + KeyValue + '&ParentId=' + KeyValue;
            delConfig('/CommonModule/Company/DeleteCompany', delparm, KeyValue.split(",").length);
        }
    }
    //刷新
    function windowload() {
        $("#gridTable").trigger("reloadGrid"); //重新载入  
    }
</script>
<div class="tools_bar leftline rightline" style="margin-bottom: 0px; margin: 1px;">
    <div class="PartialButton">
        @Html.Partial("_PartialButton")
    </div>
</div>
<div class="rightline" style="margin: 1px; margin-top: -1px;">
    <table id="gridTable"></table>
</div>
